<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // // Otaku 御宅族，简称宅
    // function Otaku(name, age) {
    //     this.name = name;
    //     this.age = age;

    //     this.hobit = 'Games';
    // }

    // // 因为缺乏锻炼的缘故， 身体令人担忧
    // Otaku.prototype.strength = 60;
    // Otaku.prototype.SayYourName = function () {
    //     console.log(`I am ${this.name}`)
    // }

    // var person = new Otaku('kavin', 22)
    // console.log(person.name)
    // console.log(person.age)
    // console.log(person.hobit)
    // person.SayYourName()


//     function Otaku(name, age) {
//         this.name = name;
//         this.age = age;

//         this.habit = 'Games';
//     }

//     Otaku.prototype.strength = 60;

//     Otaku.prototype.sayYourName = function () {
//         console.log('I am ' + this.name);
//     }

//     function objectFactory () {
//     var obj = new Object();

//     Constructor = [].shift.call(arguments);

//     obj.__proto__ = Constructor.prototype;

//     Constructor.apply(obj,arguments);

//     return obj;
// }

//     var person = objectFactory(Otaku, 'Kevin', '18')

//     console.log(person.name) // Kevin
//     console.log(person.habit) // Games
//     console.log(person.strength) // 60

//     person.sayYourName(); // I am Kevin


function Otaku (name, age) {
    this.strength = 60
    this.age = age

    // return {
    //     name:name,
    //     habit:'Games'
    // }

    return 'Games'
}


function objectFactory() {
    var obj = new Object();
    Constructor = [].shift.call(arguments)

    obj.__proto__ = Constructor.prototype

    var ret  = Constructor.apply(obj,arguments)

    return  typeof ret === 'object' ? ret : obj

};

var person = objectFactory(Otaku, 'Kevin', '18')

var person = new Otaku('kiven',18)
console.log(person.name)
console.log(person.habit)
console.log(person.strength)
console.log(person.age)

</script>

</html>